package com.jy.rhin.facade.cda;

import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.cda.*;
import com.jy.rhin.facade.cda.dto.ChanHouFSDto;
import com.jy.rhin.facade.cda.dto.ReqDto;
import com.jy.rhin.facade.cda.dto.SiWangYXZMDto;
import com.jy.rhin.facade.cda.dto.WenDangSCDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author dhl
 * @date 2023/2/20
 * @Description
 */
@Slf4j
@RequestMapping("/test")
@Api(tags = "医疗记录-住院记录相关api", hidden = true)
@RestController
public class CdaTestController {
    @Autowired
    private MenZhenZhaiYaoApplication menZhenZhaiYaoApplication;
    @Autowired
    private YuFangJZApplication yuFangJZApplication;
    @Autowired
    private ChanHouFSApplication chanHouFSApplication;
    @Autowired
    private ChanHouJCApplication chanHouJCApplication;
    @Autowired
    private ChanQianSFApplication chanQianSFApplication;
    @Autowired
    private ChanQianSCSFApplication chanQianSCSFApplication;
    @Autowired
    private HuiZhenJLApplication huiZhenJLApplication;
    @Autowired
    private GeRenJBJKXXApplication geRenJBJKXXApplication;
    @Autowired
    private XinShengErFSApplication xinShengErFSApplication;
    @Autowired
    private ChuShengYXZMApplication chuShengYXZMApplication;
    @Autowired
    private GaoXueYSFApplication gaoXueYSFApplication;
    @Autowired
    private TangNiaoBSFApplication tangNiaoBSFApplication;
    @Autowired
    private ZhongXingJSBDJApplication zhongXingJSBDJApplication;
    @Autowired
    private ZhongXingJSBSFApplication zhongXingJSBSFApplication;
    @Autowired
    private JianKangTJApplication jianKangTJApplication;
    @Autowired
    private ZhuYuanZhaiYaoApplication zhuYuanZhaiYaoApplication;
    @Autowired
    private ChuanRanBBGApplication chuanRanBBGApplication;
    @Autowired
    private CdaApplication cdaApplication;
    @Autowired
    private SiWangYXZMApplication siWangYXZMApplication;
    @Autowired
    private ErTongJKTJApplication erTongJKTJApplication;


    @ApiOperation("个人基本健康信息")
    @GetMapping("/create01")
    public String geRenJKXX(@RequestParam String gerendabs, @RequestParam String yeWuJGDM, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = geRenJBJKXXApplication.create(gerendabs, yeWuJGDM);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("门诊摘要")
    @GetMapping("/create17")
    public String menZhenZY(ReqDto req) throws Exception {
        String xml = menZhenZhaiYaoApplication.create(req);
        cdaApplication.validateAndRegister(xml, req.getAppid(), req.getEid());
        return xml;
    }

    @ApiOperation("成人健康体检")
    @GetMapping("/create16")
    public String create16(@RequestParam String tiJianBH, @RequestParam String yeWuJGDM, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = jianKangTJApplication.create(yeWuJGDM, tiJianBH);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

//    @ApiOperation("会诊记录")
//    @GetMapping("/create19")
//    public String huiZhenJL(@RequestParam String huizhendh, @RequestParam String yeWuJGDM, @RequestParam String appId, @RequestParam String eid) throws Exception {
//        String xml = huiZhenJLApplication.create(huizhendh, yeWuJGDM);
//        cdaApplication.validateAndRegister(xml, appId, eid);
//        return xml;
//    }

    @ApiOperation("预防接种")
    @GetMapping("/create09")
    public String yuFangJZ(@RequestParam String yuFangJZKBH, @RequestParam String yeWuJGDM, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = yuFangJZApplication.create(yuFangJZKBH, yeWuJGDM);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("传染病报告")
    @GetMapping("/create10")
    public String create10(@RequestParam String yiLiaoJGDM, @RequestParam String chuanRanBBGKBH, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = chuanRanBBGApplication.create(yiLiaoJGDM, chuanRanBBGKBH);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("产后访视")
    @GetMapping("/create07")
    public String chanHouFS(@RequestBody ChanHouFSDto req) throws Exception {
        String xml = chanHouFSApplication.create(req);
        //存储校验结果,校验成功,注册文档到平台
        cdaApplication.validateAndRegister(xml, req.getAppid(), req.getEid());
        return xml;
    }

    @ApiOperation("产后检查")
    @GetMapping("/create08")
    public String chanHouJC(@RequestParam String cHANHOU42TJKJCJLBH, @RequestParam String fUWUJGBH, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = chanHouJCApplication.create(cHANHOU42TJKJCJLBH, fUWUJGBH);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("产前随访")
    @GetMapping("/create06")
    public String chanQianSF(@RequestParam String CHANQIANSFJLBH, @RequestParam String fUWUJGBH, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = chanQianSFApplication.create(CHANQIANSFJLBH, fUWUJGBH);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("产前首次随访")
    @GetMapping("/create05")
    public String create05(@RequestParam String CHANQIANSFJLBH, @RequestParam String fUWUJGBH, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = chanQianSCSFApplication.create(CHANQIANSFJLBH, fUWUJGBH);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("高血压患者随访服务")
    @GetMapping("/create12")
    public String create12(@RequestParam String gaoXueYSFJLID, @RequestParam String yeWuJGDM, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = gaoXueYSFApplication.create(gaoXueYSFJLID, yeWuJGDM);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("2型糖尿病患者随访服务")
    @GetMapping("/create13")
    public String create13(@RequestParam String tangNiaoBSFID, @RequestParam String yeWuJGDM, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = tangNiaoBSFApplication.create(tangNiaoBSFID, yeWuJGDM);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("重性精神疾病患者个人信息登记")
    @GetMapping("/create14")
    public String create14(@RequestParam String jingShenBJLID, @RequestParam String yeWuJGDM, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = zhongXingJSBDJApplication.create(jingShenBJLID, yeWuJGDM);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("重性精神疾病患者随访服务")
    @GetMapping("/create15")
    public String create15(@RequestParam String jingShenBSFJLID, @RequestParam String yeWuJGDM, @RequestParam String appId, @RequestParam String eid) throws Exception {
        String xml = zhongXingJSBSFApplication.create(jingShenBSFJLID, yeWuJGDM);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @ApiOperation("住院摘要")
    @GetMapping("/create18")
    public String create18(@RequestBody ReqDto req) throws Exception {
        String xml = zhuYuanZhaiYaoApplication.create(req);
        System.out.println(xml);
        cdaApplication.validateAndRegister(xml, req.getAppid(), req.getEid());
        return xml;
    }

    @ApiOperation("新生儿访视")
    @GetMapping("/create03")
    public String xinShengEr03(@RequestBody ChanHouFSDto req) throws Exception {
        //生成
        String xml = xinShengErFSApplication.create(req.getCHANHOUFSJLBH(), req.getFUWUJGBH());
        //存储校验结果,校验成功,注册文档到平台
        cdaApplication.validateAndRegister(xml, req.getAppid(), req.getEid());
        return xml;
    }

    @ApiOperation("出生医学证明")
    @GetMapping("/create02")
    public String chuShengYXZM02(@RequestBody ChanHouFSDto req) throws Exception {
        //生成
        String xml = chuShengYXZMApplication.create(req.getCHANHOUFSJLBH(), req.getFUWUJGBH());
        //存储校验结果,校验成功,注册文档到平台
        cdaApplication.validateAndRegister(xml, req.getAppid(), req.getEid());
        return xml;
    }

    @ApiOperation("死亡医学证明")
    @PostMapping("/create11")
    public String create11(@RequestBody SiWangYXZMDto req) throws Exception {
        String xml = siWangYXZMApplication.create(req.getSiWangZH(), req.getYeWuJGDM());
        cdaApplication.validateAndRegister(xml, req.getAppId(), req.getEid());
        return xml;
    }

    @ApiOperation("儿童健康体检")
    @PostMapping("/create04")
    public String create04(@RequestParam String id,
                           @RequestParam String yeWuJGDM,
                           @RequestParam String appId,
                           @RequestParam String eid,
                           @RequestParam String tablename) throws Exception {
        String xml = erTongJKTJApplication.createErTongJKTJ(id, yeWuJGDM, tablename);
        cdaApplication.validateAndRegister(xml, appId, eid);
        return xml;
    }

    @PostMapping("createByLX")
    @ApiOperation("根据不同类型生成cda")
    public Result createByLX(@RequestBody List<WenDangSCDto> wenDangSCDto) {
        try {
            cdaApplication.createByLX(wenDangSCDto);
            return Result.success();
        } catch (Exception e) {
            log.error("生成cda失败", e);
            return Result.fail("生成失败:" + e.getMessage());
        }
    }
}
